var priceTable;
/****列表信息*/
function showBatteryPrices() {
	showLoading("查询中...");
	$.ajax( {
		url : 'batteryPrice/listPage.do',
		type : 'get',
		async:true,
		dataType : 'html',
		success : function(html) {
			$('#mainForm').html(html);
			queryBatteryPriceDatas();
			hideLoading();
			//绑定查询按钮 
		$('#searchDianChiBtn').click(function() {
			queryBatteryPrices();
		});
		$(".comboBox").kendoComboBox( {
			filter : "contains",
			suggest : true
		});
	}
	});
}
function queryBatteryPriceDatas(){
		priceTable = $('#entTable').table( {
		width : '100%',
		defaultOrderBy:"town,sort",
		defaultOrderType:"asc",
		form : {
			url : 'batteryPrice/queryList.do',
			id : '#entSearchForm',
			type : 'post',
			pageNumberText : '#pageNum'
		},
		pageable : true,
		selectable : true,
		colums : [ {
			columnName : '电池品牌',
			name : 'pinPai',
			handle : "toAddBatteryPrice",
			sortable : false
		}, {
			columnName : '电池型号',
			name : 'xingHao',
			sortable : false
		}, {
			columnName : '市场换购价',
			name : 'marketPrice',sortable : false
		}, {
			columnName : '本网换购价',
			name : 'ourPrice',
			sortable : false,sortable : false
		}, {
			columnName : '省',
			name : 'province',
			sortable : false
		}, {
			columnName : '市',
			name : 'city',
			sortable : false
		}, {
			columnName : '县',
			name : 'town',
			sortable : false
		}
		, {
			columnName : '最后更新时间',
			name : 'updateDate'
		}]
	});
}
function queryBatteryPrices() {
	showLoading("查询中...");
	queryBatteryPriceDatas();
	hideLoading();
}
//去增加
function toAddBatteryPrice(id) {
	var param = '?t=' + ts();
	if (id) {
		param += '&id=' + id;
	}
$.get('batteryPrice/toAddBatteryPrice.do' + param, function(html) {
		$('#commonDialogDiv').html(html);
		$('#commonDialogDiv').dialog( {
			modal : true,
			title : '电池区域价格管理',
			width : 896,
			height : 478,
			buttons : {
				'保存' : function() {
					saveBatteryPrice();
				},
				'取消' : function() {
					$(this).dialog('close');
				}
			},close:function(){$(this).dialog('destroy');}
		});
                addValidatorFloat();
                addValidatorInteger();
		validator = $("#DianChiForm").validate({
			rules : {
				"model.xingHao" : {
					required : true
				},
				"model.pinPai" : {
					required : true
				},
				"model.marketPrice" : {
					required : true,
					FloatCheck:true
				},
				"model.ourPrice" : {
					required : true,
					FloatCheck:true
				},
				"model.province" : {
					required : true
				},
				"model.city" : {
					required : true
				},
				"model.town" : {
					required : true
				},
				"model.sort" : {
					integer : true
				},
				"model.detailInfo":{
					maxlength : 150
				}
			},
			messages : {
				"model.xingHao" : {
					required : "必选"
				},
				"model.pinPai" : {
					required : "必选"
				},
				"model.marketPrice" : {
					required : "必填",
				    FloatCheck:"格式：整数位最多6位,小数位最多2位"
				},
				"model.ourPrice" : {
					required : "必填",
					FloatCheck:"格式：整数位最多6位,小数位最多2位"
				},
				"model.province" : {
					required : "必选"
				},
				"model.city" : {
					required : "必选"
				},
				"model.town" : {
					required : "必选"
				},
				"model.sort":{
					integer : "只能填写大于0数字"
				},
				"model.detailInfo" : {
					maxlength : "不得超过150字"
				}
			},
			errorPlacement : function(error, element) {
				error.appendTo(element.parent());
				element.removeClass("error");
		    }
		});
	});
}
//去保存
function saveBatteryPrice() {
	if (validator.form()) {
		$('#DianChiForm').ajaxSubmit( {
			url : 'batteryPrice/saveBatteryPrice.do',
			type : 'post',
			dataType : 'json',
			success : function(data) {
				if (data.success) {
					showDialog('保存成功');
					$('#commonDialogDiv').dialog('close');
					queryBatteryPrices();
				} else {
					showDialog('保存失败，' + data.message);
				}
			}
		});
	}
}

//批量删除 
function toDeleteBatteryPrices() {
	var ids = '';
	$('.ids').each(function() {
		if (this.checked == true) {
			ids += 'ids=' + this.value + '&';
		}
	});
	if (ids.length == 0) {
		showDialog('请至少选择一条记录！');
		return;
	}
	$('#commonDialogDiv').html('<p>确定要删除记录信息？</p>');
	$('#commonDialogDiv').dialog( {
		modal : true,
		width : 250,
		height : 160,
		buttons : {
			'确定' : function() {
				$(this).dialog('close');
				$.ajax( {
					url : 'batteryPrice/delete.do?' + ids,
					type : 'get',
					dataType : 'json',
					success : function(data) {
						if (data.success) {
							queryBatteryPrices();
						} else {
							showDialog('删除失败，原因：' + data.message);
						}
					}
				});
			},
			'取消' : function() {
				$(this).dialog('close');
			}
		},close:function(){$(this).dialog('destroy');}
	});
}

function promptinfo()
{
    var s1 = document.getElementById('s1');
    var s2 = document.getElementById('s2');
    var s3 = document.getElementById('s3');
}

function getShi(obj,shiId,quId){
				if($(obj).val()==''){
					$("#"+shiId).empty();
					$("#"+shiId).html("<option value=''>选择市</option>");
					$("#"+quId).empty();
					$("#"+quId).html("<option value=''>选择区</option>");
					return;
				}
				$.ajax({
					url:'district/queryCityByProvince.do?t='+(new Date()),
					type:'post',
					data:{pname:$(obj).val()},
					dataType:'json',
					success:function(json){
						var shis = json;
						$("#"+quId).empty();
						$("#"+quId).html("<option value=''>选择区</option>");
						var html = "<option value=''>选择市</option>";
						for(var i=0;i<shis.length;i++){
							html +="<option value='"+shis[i].name+"'>"+shis[i].name+"</option>";
						}
						$('#'+shiId).html(html).parent().css('display','');
					}
				});
			}
			
			function getQu(obj,quId){
				$.ajax({
					url:'district/queryTownByCity.do?t'+(new Date()),
					type:'post',
					data:{pname:$(obj).val()},
					dataType:'json',
					success:function(json){
						var qus = json;
						var html = "<option value=''>选择区</option>";
						for(var i=0;i<qus.length;i++){
							html +="<option value='"+qus[i].name+"'>"+qus[i].name+"</option>";
						}
						$('#'+quId).html(html).parent().css('display','');
					}
				});
			}

			function ajaxQueryPrice(){
				var b_province=$("#b_province").val();
				var shiId=$("#shiId").val();
				var quId=$("#quId").val();
				var model_pinPai=$("#model_pinPai").val();
				var model_xingHao=$("#model_xingHao").val();
				
				if(b_province&&shiId&&quId&&model_pinPai&&model_xingHao){
				$.ajax({
					url:'dianChi/ajaxQueryPrice.do?t'+(new Date()),
					type:'post',
					data:{'province':b_province,'city':shiId,'town':quId,'pinPai':model_pinPai,'xingHao':model_xingHao},
					dataType:'json',
					success:function(data){
						if (data.success) {
							$("#model_marketPrice").val(data.marketPrice);
							$("#model_ourPrice").val(data.ourPrice);
						} else {
						//	showDialog('查询失败');
						}
					}
				});
				}
			}